export  default  class TimeTool {


    private static m_useTrueDeltaTime=true;
    private static m_deltatime=0;

    ///获取帧时间间隔 以秒为单位
    public static get DeltaTime():number
    {
        if (TimeTool.m_useTrueDeltaTime) 
        {
            return Laya.timer.delta/1000;
        }
        if (TimeTool.m_deltatime==0) 
        {
            TimeTool.m_deltatime=Laya.timer.delta/1000;
            if (TimeTool.m_deltatime>=0.02) 
            {
                TimeTool.m_deltatime=0.02;
            }
            
        }
         return TimeTool.m_deltatime;   
    }


    public static get CurrentTime()
    {
        var nowdate:Date = new Date(); 
        //创建新的日期对象，用来获取现在的时间 
        var year:Number = nowdate.getFullYear(); 
        //获取当前的年份 
        var month:Number = nowdate.getMonth()+1; 
        //获取当前的月份，因为数组从0开始用0-11表示1-12月，所以要加1 
        var date:Number = nowdate.getDate(); 
        //获取当前日期 
        var day:Number = nowdate.getDay(); 
        //获取当年的星期 
        var hour:Number = nowdate.getHours(); 
        //获取当前小时 
        var minute:Number = nowdate.getMinutes(); 
        //获取当前的分钟 
        var second:Number = nowdate.getSeconds(); 
        //获取当前的秒钟 
        //trace("今天是" + year + "年" + month + "月" + date+"日" + "星期" + day + "现在时刻" + hour + ":" + minute+":" + second); 
        var currenttime =year+":"+ hour + ":" + minute+":" + second;
     
        return currenttime;
    } 


    
    public static  SECONDS_IN_DAY = 60 * 60 * 24;
    public static   MILLIS_IN_DAY = 1000 * TimeTool.SECONDS_IN_DAY;
    public static  isSameDayOfMillisInternal( ms1:number, ms2:number) 
    {
        let interval =Math.abs(ms1 - ms2);
        return interval <TimeTool.MILLIS_IN_DAY
                && TimeTool.toDay(ms1) ==TimeTool.toDay(ms2);
    }

    public static  isSameDayOfMillis( ms1:number, ms2:number) 
    {
        let day1= TimeTool.toDay(ms1);
        let day2=TimeTool.toDay(ms2);
        return day1==day2;
    }

    private static  toDay( millis:number) 
    {
        let date=new Date(millis);
        return date.getDate();
    }
    
    public static IsCurrenTimeInRange(mindata:number,maxdata)
    {
        let date=new Date();
       let time= date.getTime();
       if (time<mindata||time>maxdata) 
       {
           return false;
       }
       return true;
    }

    static GetTimeFormat(time:number,issecond:boolean=true)
    { 
        let second=0;
        if (issecond)
            second=Math.floor(time);
        else
            second=Math.floor(time/1000);
        let hourstr="";
        let minutestr="";
        let secondsstr="";

        let hours=Math.floor(second/3600);
        if (hours>0) 
        {
            if (hours<10)   hourstr="0"+hours;
            else hourstr=hours.toString();
            hourstr+=":";
        }
        let minis=Math.floor((second- hours*3600)/60);
        if (minis<10) 
          minutestr="0"+minis;
        else
          minutestr=minis.toString();

        let seconds=second- hours*3600- minis*60;
        if (seconds<10) 
        {
          secondsstr="0"+seconds;
        }
        else{
            secondsstr=seconds.toString();
        }
        return (hourstr+minutestr+":"+secondsstr)
    }


    public static get Time()//秒
    {
       return Laya.Browser.now()/1000;
    }
}